%{
#define PROGRAM 	110
#define PROCEDURE 	111
#define FUNCTION 	112
#define CONST 		113
#define TYPE 		114
#define VAR 		115
#define ARRAY 		116
#define BOOLEAN 	117	
#define CHAR 		118
#define INTEGER 	119
#define REAL 		120
#define RECORD 		121
#define BEGIN_ 		122
#define END 		123
#define OF 		124
#define IF 		125
#define THEN 		126
#define ELSE 		127
#define FOR 		128
#define TO 		129
#define DOWNTO 		130
#define DO 		131
#define NEW 		132
#define DISPOSE		133 
#define VIRGULA 	134
#define PONTO_E_VIRGULA 135
#define DOIS_PONTOS 	136
#define PONTO 		137
#define OPERADOR_DE_ATRIBUICAO 	138
#define OPERADOR_DE_SUBFAIXA 	139
#define SOMA 		140
#define SUBTRACAO 	141
#define ASTERISCO 	142
#define DIVISAO 	143
#define ENDERECO 	144
#define VALOR_DE_PONTEIRO 	145
#define MOD 		146
#define AND 		147
#define OR 		148
#define NOT 		149
#define IGUALDADE 	150
#define DESIGUALDADE 	151
#define MENOR 		152
#define MENOR_OU_IGUAL 	153
#define MAIOR 		154
#define MAIOR_OU_IGUAL 	155
#define ABRE_PARENTESIS 156
#define FECHA_PARENTESIS	 157
#define ABRE_COLCHETE 	158
#define FECHA_COLCHETE 	159
#define CONDICIONAL_TERNARIO 	160
#define VALOR 		161
#define IDENTIFICADOR 	162
#define ESPACO		163
#define FIM_DE_ARQUIVO	164

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char messages[1000] = ""; 

unsigned int lc = 0;
unsigned int ln;
unsigned int ncol = 0;

void mensagemErro(char *message, unsigned int ln) {
char buffer[50];
sprintf(buffer, "Erro na linha %i %s.\n", ln, message);
strcat(messages, buffer);
}
 
void mostrarMensagens() {
if(strlen(messages) > 0){
		printf("\n%s", messages);
	}

	printf("%d lines\n%d colunas\n", lc,ncol);
} 

%}

caractere		\'.\'
flutuante		[+-]?[0-9]+\.[0-9]+([eE][+-]?[0-9]{1,2})?
inteiro			[+-]?[0-9]+
identificador	[a-zA-Z][a-zA-Z0-9_]*
espaco			[ \t]+
erro			.

%x comentario string


%%

[pP]rogram|PROGRAM		{ ncol+=yyleng; return PROGRAM;}

%%

int main(int argc, char** argv) {
	yyin = fopen(argv[1], "r");
	
	while (yylex());	
	mostrarMensagens( );
	return EXIT_SUCCESS;
}
int yywrap() {
	return 1;
}

